<template>
  <van-loading v-if="loading" color="#1989fa" size="20px"></van-loading>
  <van-icon
    v-else
    color="#777"
    :name="value ? 'star' : 'star-o'"
    :class="value ? 'like' : ''"
    :loading="loading"
    @click="onCollect"
  ></van-icon>
</template>

<script>
import { addShou, delShou } from "@/api/user.js";
export default {
  data() {
    return {
      loading: false,
    };
  },
  props: {
    value: {
      type: Boolean,
      required: true,
    },
    aut_id: {
      type: [String, Number],
      require: true,
    },
  },
  methods: {
    async onCollect() {
      this.loading = true;
      try {
        if (this.value) {
          const { data } = await delShou(this.aut_id);
          // console.log(data);
          this.loading = false;

          this.$emit("input", !this.value);
        } else {
          const { data } = await addShou(this.aut_id);
          this.loading = false;

          console.log(data);
          this.$emit("input", !this.value);
        }
      } catch (err) {
        this.loading = false;

        console.log(err);
        this.$toast.fail("操作失败，请重试");
      }
    },
  },
};
</script>

<style lang="less" scoped>
.like {
  color: #ffa500 !important;
}
</style>